package com.atguigu.gmall.item.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.service.SkuDetailService;
import com.atguigu.gmall.model.to.SkuDetailTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 卡尼奶
 * @Date 2022/5/22 17:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/rpc/inner/item")
public class SkuItemDetailRpcController {

    @Autowired
    private SkuDetailService skuDetailService;


    /**
     * 根据SkuId获取商品详情
     * @param skuId
     * @return
     */
    @GetMapping("/sku/detail/{skuId}")
    public Result<SkuDetailTo> getSkuDetail(@PathVariable("skuId")Long skuId){
        //代理类对象CGLIB动态代理
        SkuDetailTo skuDetailTo = skuDetailService.getSkuDetail(skuId);

        //增加商品热度
        skuDetailService.incrHotScore(skuId);

        return Result.ok(skuDetailTo);
    }
}
